#coding=utf-8
'''
Created on 2016年8月18日

@author: hexq
'''
import ConfigParser
# from push_button import PushButton
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtWebKit import*
from PyQt4 import QtCore, QtGui
from PyQt4 import uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from PyQt4.QtNetwork import *
import sys
from caches import *
from lszbHelper import *
import traceback
import os
import re

reload(sys)
sys.setdefaultencoding('utf-8')

# pinyins = PinYin()
# pinyins.load_word()

wenguans_value_ini = "[1, 1, 1, 1, 1, 1, 0, 0]"
ini_generals = {"曹洪": 50301, "邓艾": 51901, "典韦": 61401, "孙坚": 50101, "黄盖": 51301, 
                "关兴": 50302, "张郃": 51001, "乐进": 50601, "许褚": 60101, "于禁": 51002, 
                "董卓": 50701, "颜良": 50201, "张飞": 60102, "周泰": 50801, "甄姬": 51201, 
                "夏侯渊": 60302, "凌统": 51101, "陆逊": 61201, "姜维": 51701, "吕蒙": 60301, 
                "关平": 50902, "张苞": 50901, "太史慈": 61501, "曹仁": 50802, "孙尚香": 50702, 
                "文丑": 50202, "孟获": 50501, "庞德": 60201, "徐晃": 61701, "祝融": 50502, 
                "魏延": 52001, "孙策": 61601, "张辽": 61301,"夏侯惇":60202}
# qi_list_ini = [1,1,1,1,1,1,1,1,1]
# gong_list_ini = [1,1,1,1,1,1,1,1]
# bu_list_ini = [1,1,1,1,1,1,1,1,1,1,1]
# che_list_ini = [1,1,1,1,1]
qi_lists = [u"庞德", u"徐晃", u"孙策",u"文丑", u"孟获", u"祝融", u"魏延", u"张辽", u"颜良",u"夏侯惇"]
gong_lists= [u"太史慈", u"陆逊", u"吕蒙", u"夏侯渊", u"曹洪", u"董卓", u"关兴", u"孙尚香"] 
bu_lists= [u"张飞", u"典韦", u"许褚", u"孙坚", u"张苞", u"曹仁", u"张郃", u"周泰", u"关平", u"于禁", u"邓艾"]
che_lists = [u"乐进", u"姜维", u"甄姬", u"凌统", u"黄盖"]

citybuilding_lists = []
#12,13分别代表农田和和市场
for i in range(12,26):
    citybuilding_lists.append(i)
cityDict = {u"12":u"市场",u"13":u"农田",u"14":u"酒馆",u"15":u"宴会厅",u"16":u"乐坊",
            u"17":u"赌场",u"18":u"驿站",u"19":u"丰碑",u"20":u"粮仓",u"21":u"银仓",u"22":u"监狱",u"23":u"术士工坊",u"24":u"钱庄",u"25":u"军机处"}

bingfa_lists = []
for i in range(1,33):
    bingfa_lists.append(i)
bingfaDict = {"2":u"初级步战","6":u"斩骑兵法","7":u"厚甲兵法","12":u"重步兵法","13":u"铁甲兵法","19":u"步战专精","23":u"防卫兵法","29":u"神级步战",
              "3":u"初级骑战","8":u"破步兵法","9":u"重骑兵法","14":u"冲锋兵法","15":u"狼骑兵法","20":u"骑战专精","24":u"击杀兵法","30":u"神级骑战",
              "4":u"初级弓战","10":u"穿骑兵法","11":u"碎甲兵法","16":u"强弓兵法","17":u"齐射兵法","21":u"弓战专精","25":u"远箭兵法","31":u"神级弓战",
              "1":u"怒酒战法","5":u"初级车战","18":u"摧城兵法","22":u"车战专精","26":u"战车兵法","27":u"统帅兵法","28":u"减怒兵法","32":u"神级车战"}

pos_ini = [0,0,0,0,0]
zhugongbaowu_ini = [0,0,0,0,0,0]

def errors(logs):
    f = open(logs,'a')
    traceback.print_exc(file=f)
    f.flush()
    f.close()

# def delLog(pwd):
#     if os.path.exists(pwd):
#         os.remove(pwd)
        
def delLog(topdown=True): 
    dir = os.getcwd()
    for root, dirs, files in os.walk(dir, topdown): 
        for name in files: 
#             if re.findall("error.*.txt*", name) <> [] or re.findall("LsAssistant.*.msi", name) <> []:
            if re.findall("error.*.txt*", name) <> []:
                os.remove(os.path.join(root, name))

cp = ConfigParser.ConfigParser()
configpwd = 'config.conf'
#获取配置信息值
def getConfig(key):
    cp.read(configpwd)
    value = cp.get('server',key)
    return value

#更改配置
def setConfig(key,value):
    cp.read(configpwd)
    cp.set('server',key,value)
    fp = open(configpwd, "w")
    cp.write(fp)
    fp.close()

#去除文件空行
def delblankline(infile,outfile):
    infopen = open(infile,'r')
    outfopen = open(outfile,'w')
    lines = infopen.readlines()
    for line in lines:
        if line.split():
            outfopen.writelines(line)
        else:
            outfopen.writelines("")
    infopen.close()
    outfopen.close()
    os.remove(infile)
    os.rename(outfile, infile)

class EmittingStream(QObject):
    textWritten = pyqtSignal(str)
    def write(self, text):
        self.textWritten.emit(str(text))
        
        
# class myThread(threading.Thread):
#     def __init__(self):
#         threading.Thread.__init__(self)
#         self.stopped = 0
#     def run(self):
#         getCache('cursors').insertText(str('aaaaaaaaaaaaaaaa')+'\n')
#         getCache('cursors').insertText(str('ddd')+'\n')
#         print getCache('cursors')
#         print getCache('textEdit')
#         getCache('textEdit').setText('ddd')
# #         getCache('tab2').setText('sssss')
# #         if self.stopped == 0:
# #             get_urlroot_index()


class myThread(QThread):
    trigger = pyqtSignal()
    tstop = True
    
    #开始运行线程
    def run(self):
        
        setCache('needPlayerRole', 1)
        setCache('needGeneralUpgrade', 30)
        setCache('addguozhan', 1)
#         setCache('xiaojingyan', 0)
#         setCache('firstClear', 0)
        #开启监听
        self.getListeners = getListener()
        self.getListeners.setDaemon(True)
        self.getListeners.start()
#         setAllCofig()

        l = lszbHelper()
        
        l.getCjAndOpener()
        while True:
            try:
                if getCache('playerheaders') is not None:
                    time.sleep(1)
                    l.gettavern()
                    time.sleep(1)
                    l.getplayerlv()
                    time.sleep(1)
                    while True:
                        time.sleep(1)
                        l.doSomething()
                        prints('准备清空日志')
                        time.sleep(1)
                        self.trigger.emit()         #循环完毕后发出信号
                else:
                    time.sleep(1)
                    prints('请登陆游戏重新获取cookies')
                    time.sleep(1)
                    self.trigger.emit()
            except:
                errors('error1.txt')
#                 output = open('error1.txt','a')
#                 output.write('异常'+str(e)+'\n')
#                 output.close()
                print("重连~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                self.trigger.emit()         #循环完毕后发出信号
                continue
        
    def stop(self):
        
        self.getListeners.stop()
        
        self.getListeners.join()
#         self.getListeners.terminate()
        self.tstop = False


class myThread2(QThread):
    trigger = pyqtSignal()
    tstop = True
    
    #开始运行线程
    def run(self):
        
#         #开启监听
#         getListeners = getListener()
#         getListeners.start()
        
        l = lszbHelper()
        
        l.getCjAndOpener()
        while True:
            try:
                if getCache('playerheaders') is not None:
#                     time.sleep(1)
#                     l.gettavern()
#                     time.sleep(1)
#                     l.getplayerlv()
#                     time.sleep(1)
                    while True:
#                         time.sleep(1)
                        l.doSomething2()
#                         time.sleep(1)
#                         self.trigger.emit()         #循环完毕后发出信号
                else:
                    time.sleep(1)
                    prints('请登陆游戏重新获取cookies')
                    time.sleep(1)
#                     self.trigger.emit()
            except Exception as e:
                print("重连2~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                errors('error2.txt')
#                 output = open('error2.txt','a')
#                 output.write('异常'+str(e)+'\n')
#                 output.close()
#                 self.trigger.emit()         #循环完毕后发出信号
                continue
        
    def stop(self):
        self.tstop = False

class myThread3(QThread):
    trigger = pyqtSignal()
    tstop = True
    
    #开始运行线程
    def run(self):
        
#         #开启监听
#         getListeners = getListener()
#         getListeners.start()
        #赌博初始化
        setCache('ifpurify', 0)
#         #庆典初始化
#         setCache('iscelebration', 0)
        l = lszbHelper()
        
        l.getCjAndOpener()
        while True:
            try:
                if getCache('playerheaders') is not None:
#                     time.sleep(1)
#                     l.gettavern()
#                     time.sleep(1)
#                     l.getplayerlv()
#                     time.sleep(1)
                    while True:
#                         time.sleep(1)
                        l.doSomething3()
#                         time.sleep(1)
#                         self.trigger.emit()         #循环完毕后发出信号
                else:
                    time.sleep(1)
                    prints('请登陆游戏重新获取cookies')
                    time.sleep(1)
#                     self.trigger.emit()
            except Exception as e:
                print("重连3~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                errors('error3.txt')
#                 output = open('error3.txt','a')
#                 output.write('异常'+str(e)+'\n')
#                 output.close()
#                 self.trigger.emit()         #循环完毕后发出信号
                continue
            
    def stop(self):
        self.tstop = False
        
class myThread4(QThread):
    trigger = pyqtSignal()
    tstop = True
    
    #开始运行线程
    def run(self):
        
#         #开启监听
#         getListeners = getListener()
#         getListeners.start()
#         #赌博初始化
#         setCache('ifpurify', 0)
#         #庆典初始化
#         setCache('iscelebration', 0)
        l = lszbHelper()
        
        l.getCjAndOpener()
        while True:
            try:
                if getCache('playerheaders') is not None:
#                     time.sleep(1)
#                     l.gettavern()
#                     time.sleep(1)
#                     l.getplayerlv()
#                     time.sleep(1)
                    while True:
#                         time.sleep(1)
                        l.doSomething4()
#                         time.sleep(1)
#                         self.trigger.emit()         #循环完毕后发出信号
                else:
                    time.sleep(1)
                    prints('请登陆游戏重新获取cookies')
                    time.sleep(1)
#                     self.trigger.emit()
            except Exception as e:
                print("重连4~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                errors('error4.txt')
#                 output = open('error4.txt','a')
#                 output.write('异常'+str(e)+'\n')
#                 output.close()
#                 self.trigger.emit()         #循环完毕后发出信号
                continue
        
    def stop(self):
        self.tstop = False
        
class myThread5(QThread):
    trigger = pyqtSignal()
    tstop = True
    
    #开始运行线程
    def run(self):
        
        while True:
            try:
                for i in range(0,9):
                    if i == 9 :
                        #重置排除建筑id的list
                        prints("开始清理排除建筑id的list")
                        setCache("expBuild", [])
                    time.sleep(5)
            except Exception as e:
                print("重连5~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                errors('error5.txt')
                continue
        
    def stop(self):
        self.tstop = False
        
# class myThread5(QThread):
#     trigger = pyqtSignal()
#     tstop = True
#     
#     #开始运行线程
#     def run(self):
#         
#         l = lszbHelper()
#         
#         l.getCjAndOpener()
#         while True:
#             try:
#                 if getCache('playerheaders') is not None:
#                     while True:
#                         l.doSomething5()
# #                         self.trigger.emit()         #循环完毕后发出信号
#                 else:
#                     time.sleep(1)
#                     prints('请登陆游戏重新获取cookies')
#                     time.sleep(1)
# #                     self.trigger.emit()
#             except Exception as e:
#                 print("重连5~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
#                 errors('error5.txt')
# #                 output = open('error4.txt','a')
# #                 output.write('异常'+str(e)+'\n')
# #                 output.close()
# #                 self.trigger.emit()         #循环完毕后发出信号
#                 continue
#         
#     def stop(self):
#         self.tstop = False

class MyConsole(QWidget):
    trigger = pyqtSignal()
    def __init__(self,parent):
        QWidget.__init__(self)
        self.parent = parent
        
        self.initUI()
        
        
        
        tabs = getCache('tabs')
        
#         #重定向输出
        sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
        sys.stderr = EmittingStream(textWritten=self.normalOutputWritten)
        
        self.tab2 = QTextEdit()
        setCache('tab2', self.tab2)    
        tabs.addTab(self.tab2,u"日志输出")
        
        
        self.tab2 = getCache('tab2')
        
        prints('请前往控制台开始操作')
        
        setCache('cursors', self.cursor)
        
        self.thread = myThread()
        
        self.thread2 = myThread2()
     
        self.thread3 = myThread3()
        self.thread4 = myThread4()
        self.thread5 = myThread5()
    #初始化UI    
    def initUI(self):
        
        #了变量名就是可变的情况
        self.BL = locals()
        
        pe = QPalette()  
        pe.setColor(QPalette.WindowText,Qt.red)#设置字体颜色  
        #获取config配置
        try:
            try:
                posvalue = getConfig('pos')
                if not isinstance(posvalue, list):
                    posvalue = eval(posvalue)
                    if not isinstance(posvalue, list):
                        posvalue = pos_ini
                        setConfig('pos', posvalue)
                    else:
                        if len(posvalue) <> len(pos_ini):
                            posvalue = pos_ini
                            setConfig('pos', posvalue)
            except Exception as e:
                posvalue = pos_ini
                output = open(configpwd,'a')
                output.write('\npos = %s'%posvalue)
                output.close()
            fires_value = getConfig('fires')
#             bingfa_value= getConfig('bingfa')
#             eventGem_value= getConfig('eventGem')
            three_value= getConfig('three')
#             ifbig_value = getConfig('ifbig')
#             if1v2_value = getConfig('if1v2')
#             upgradeBaowu_value = getConfig('upgradeBaowu')
            guofang_value = getConfig('guofang')
            except_value = getConfig('excepts')
            usernames_value = getConfig('usernames')
            try:
                three_value2= getConfig('three2')
            except Exception as e:
                three_value2 = '0'
                output = open(configpwd,'a')
                output.write('\nthree2 = 0')
                output.close()
            try:
                CheckPutong_value= getConfig('CheckPutong')
                CheckGuanka_value= getConfig('CheckGuanka')
                CheckGunshi_value= getConfig('CheckGunshi')
                CheckSenlin_value= getConfig('CheckSenlin')
                CheckCaoyuan_value= getConfig('CheckCaoyuan')
                CheckShuiyu_value= getConfig('CheckShuiyu')
                CheckHuchenghe_value= getConfig('CheckHuchenghe')
                CheckManzucheng_value= getConfig('CheckManzucheng')
                CheckXiagu_value= getConfig('CheckXiagu')
                CheckGangkou_value= getConfig('CheckGangkou')
            except Exception as e:
                CheckPutong_value= '1'
                CheckGuanka_value= '1'
                CheckGunshi_value= '1'
                CheckSenlin_value= '1'
                CheckCaoyuan_value= '1'
                CheckShuiyu_value= '1'
                CheckHuchenghe_value= '1'
                CheckManzucheng_value= '1'
                CheckXiagu_value= '1'
                CheckGangkou_value= '1'
                
                output = open(configpwd,'a')
                output.write('\nCheckPutong = 1\n')
                output.write('CheckGuanka = 1\n')
                output.write('CheckGunshi = 1\n')
                output.write('CheckSenlin = 1\n')
                output.write('CheckCaoyuan = 1\n')
                output.write('CheckShuiyu = 1\n')
                output.write('CheckHuchenghe = 1\n')
                output.write('CheckManzucheng = 1\n')
                output.write('CheckXiagu = 1\n')
                output.write('CheckGangkou = 1')
                output.close()
            try:
                #文官事件选择
                wenguans_value = getConfig('wenguans')
                if not isinstance(wenguans_value, list):
                    wenguans_value = eval(wenguans_value)
#                     print len(wenguans_value)
#                     print len(wenguans_value_ini)
                    if len(wenguans_value) <> len(eval(wenguans_value_ini)):
                        wenguans_value = wenguans_value_ini 
                        setConfig('wenguans', wenguans_value)
            except Exception as e:
                wenguans_value = wenguans_value_ini
                output = open(configpwd,'a')
                output.write('\nwenguans = %s\n'%wenguans_value_ini)
                output.close()
            try:
                #兵种升级选择
                qilist_value = getConfig('qilist')
                gonglist_value = getConfig('gonglist')
                bulist_value = getConfig('bulist')
                chelist_value = getConfig('chelist')
            except Exception as e:
                qilist_value = []
                gonglist_value = []
                bulist_value = []
                chelist_value= []
                output = open(configpwd,'a')
                output.write('\nqilist = %s\n'%qilist_value)
                output.write('gonglist = %s\n'%gonglist_value)
                output.write('bulist = %s\n'%bulist_value)
                output.write('chelist = %s\n'%chelist_value)
                output.close()
            try:
                citybuilding_value = getConfig('citybuilding')
            except Exception as e:
                citybuilding_value = []
                output = open(configpwd,'a')
                output.write('\ncitybuilding = %s\n'%citybuilding_value)
                output.close()
            try:
                bingfas_value = getConfig('bingfas')
            except Exception as e:
                bingfas_value = []
                output = open(configpwd,'a')
                output.write('\nbingfas = %s\n'%citybuilding_value)
                output.close()
            try:
                zhugongbaowu_value = getConfig('zhugongbaowu')
                if not isinstance(zhugongbaowu_value, list):
                    zhugongbaowu_value = eval(zhugongbaowu_value)
                if not isinstance(zhugongbaowu_value, list) or len(zhugongbaowu_value) <> len(zhugongbaowu_ini):
                    zhugongbaowu_value = zhugongbaowu_ini
                    setConfig('zhugongbaowu', zhugongbaowu_value)
            except Exception as e:
                zhugongbaowu_value = zhugongbaowu_ini
                output = open(configpwd,'a')
                output.write('\nzhugongbaowu = %s\n'%zhugongbaowu_value)
                output.close()
            try:
                zhongcheng_vallue = str(getConfig('zhongcheng'))
                
            except Exception as e:
                zhongcheng_vallue = '1'
                output = open(configpwd,'a')
                output.write('\nzhongcheng = %s\n'%zhongcheng_vallue)
                output.close()
            try:
                threeGold_value = str(getConfig('threeGold'))
            except Exception as e:
                threeGold_value = 0
                output = open(configpwd,'a')
                output.write('\nthreeGold = %s\n'%threeGold_value)
                output.close()
            try:
                threeGold2_value = str(getConfig('threeGold2'))
            except Exception as e:
                threeGold2_value = 0
                output = open(configpwd,'a')
                output.write('\nthreeGold2 = %s\n'%threeGold2_value)
                output.close()
            try:
                yinbizhuanpanGold_value = str(getConfig('yinbizhuanpanGold'))
            except Exception as e:
                yinbizhuanpanGold_value = 0
                output = open(configpwd,'a')
                output.write('\nyinbizhuanpanGold = %s\n'%yinbizhuanpanGold_value)
                output.close()
            try:
                laobaowuGold_value = str(getConfig('laobaowuGold'))
            except Exception as e:
                laobaowuGold_value = 0
                output = open(configpwd,'a')
                output.write('\nlaobaowuGold = %s\n'%laobaowuGold_value)
                output.close()
            try:
                serverid_value = str(getConfig('serverid'))
                servername_value = str(getConfig('servername'))
            except Exception as e:
                serverid_value = '1'
                servername_value = 'aoshitang'
                output = open(configpwd,'a')
                output.write('\nserverid = %s\n'%serverid_value)
                output.write('\nservername = %s\n'%servername_value)
                output.close()
            try:
                ifFenbin_value = str(getConfig('ifFenbin'))
            except Exception as e:
                ifFenbin_value = '0'
                output = open(configpwd,'a')
                output.write('\nifFenbin = %s\n'%ifFenbin_value)
                output.close()
            try:
                #是否永久武将
                ifyongjiu_value = str(getConfig('ifyongjiu'))
            except Exception as e:
                ifyongjiu_value = '0'
                output = open(configpwd,'a')
                output.write('\nifyongjiu = %s\n'%ifyongjiu_value)
                output.close()
        except Exception as e:
            posvalue = pos_ini
            fires_value = '0'
#             bingfa_value = '0'
#             eventGem_value = '0'
#             ifbig_value = '1'
#             if1v2_value = '1'
#             upgradeBaowu_value = '0'
            guofang_value = '12'
            except_value = ''
            usernames_value = ''
            three_value = '0'
            three_value2 = '0'
            CheckPutong_value= '1'
            CheckGuanka_value= '1'
            CheckGunshi_value= '1'
            CheckSenlin_value= '1'
            CheckCaoyuan_value= '1'
            CheckShuiyu_value= '1'
            CheckHuchenghe_value= '1'
            CheckManzucheng_value= '1'
            CheckXiagu_value= '1'
            CheckGangkou_value= '1'
            wenguans_value = wenguans_value_ini
            
            qilist_value = []
            gonglist_value = []
            bulist_value = []
            chelist_value= []
            citybuilding_value = []
            bingfas_value = []
            zhugongbaowu_value = zhugongbaowu_ini
            zhongcheng_vallue = '1'
            threeGold_value = '0'
            threeGold2_value = '0'
            yinbizhuanpanGold_value = 0
            laobaowuGold_value = 0
            serverid_value = '1'
            servername_value = 'aoshitang'
            ifFenbin_value = '0'
            ifyongjiu_value = '0'
            
            output = open(configpwd,'w')
            output.write('[server]\n')
            output.write('pos = %s\n'%posvalue)
            output.write('fires = 0\n')
#             output.write('bingfa = 0\n')
#             output.write('ifbig = 1\n')
#             output.write('if1v2 = 1\n')
#             output.write('upgradeBaowu = 0\n')
            output.write('guofang = 12\n')
            output.write('excepts = \n')
            output.write('usernames = \n')
            output.write('three = 0\n')
            output.write('three2 = 0\n')
            output.write('CheckPutong = 1\n')
            output.write('CheckGuanka = 1\n')
            output.write('CheckGunshi = 1\n')
            output.write('CheckSenlin = 1\n')
            output.write('CheckCaoyuan = 1\n')
            output.write('CheckShuiyu = 1\n')
            output.write('CheckHuchenghe = 1\n')
            output.write('CheckManzucheng = 1\n')
            output.write('CheckXiagu = 1\n')
            output.write('CheckGangkou = 1\n')
            output.write('wenguans = %s\n'%wenguans_value_ini)
            output.write('qilist = %s\n'%qilist_value)
            output.write('gonglist = %s\n'%gonglist_value)
            output.write('bulist = %s\n'%bulist_value)
            output.write('chelist = %s\n'%chelist_value)
            output.write('\ncitybuilding = %s\n'%citybuilding_value)
            output.write('\nbingfas = %s\n'%bingfas_value)
            output.write('\nzhugongbaowu = %s\n'%zhugongbaowu_value)
            output.write('\nzhongcheng = %s\n'%zhongcheng_vallue)
            output.write('\nthreeGold = %s\n'%threeGold_value)
            output.write('\nthreeGold2 = %s\n'%threeGold2_value)
            output.write('\nyinbizhuanpanGold = %s\n'%yinbizhuanpanGold_value)
            output.write('\nlaobaowuGold = %s\n'%laobaowuGold_value)
            output.write('\nserverid = %s\n'%serverid_value)
            output.write('\nservername = %s\n'%servername_value)
            output.write('\nifFenbin = %s\n'%ifFenbin_value)
            output.write('\nifyongjiu = %s\n'%ifyongjiu_value)
            output.close()
        if not os.path.exists(configpwd):
            output = open(configpwd,'w')
            output.write('[server]\n')
            output.write('pos = %s\n'%pos_ini)
            output.write('fires = 0\n')
#             output.write('bingfa = 1\n')
#             output.write('ifbig = 1\n')
#             output.write('if1v2 = 1\n')
#             output.write('upgradeBaowu = 0\n')
            output.write('guofang = 12\n')
            output.write('excepts = \n')
            output.write('usernames = \n')
            output.write('three = 0\n')
            output.write('three2 = 0\n')
            output.write('CheckPutong = 1\n')
            output.write('CheckGuanka = 1\n')
            output.write('CheckGunshi = 1\n')
            output.write('CheckSenlin = 1\n')
            output.write('CheckCaoyuan = 1\n')
            output.write('CheckShuiyu = 1\n')
            output.write('CheckHuchenghe = 1\n')
            output.write('CheckManzucheng = 1\n')
            output.write('CheckXiagu = 1\n')
            output.write('CheckGangkou = 1\n')
            output.write('wenguans = %s\n'%wenguans_value_ini)
            output.write('qilist = []\n')
            output.write('gonglist = []\n')
            output.write('bulist = []\n')
            output.write('chelist = []\n')
            output.write('\ncitybuilding = []\n')
            output.write('\nbingfas = []\n')
            output.write('\nzhugongbaowu = %s\n'%zhugongbaowu_value)
            output.write('\nzhongcheng = %s\n'%zhongcheng_vallue)
            output.write('\nthreeGold = %s\n'%threeGold_value)
            output.write('\nthreeGold2 = %s\n'%threeGold2_value)
            output.write('\nyinbizhuanpanGold = %s\n'%yinbizhuanpanGold_value)
            output.write('\nlaobaowuGold = %s\n'%laobaowuGold_value)
            output.write('\nserverid = %s\n'%serverid_value)
            output.write('\nservername = %s\n'%servername_value)
            output.write('\nifFenbin = %s\n'%ifFenbin_value)
            output.write('\nifyongjiu = %s\n'%ifyongjiu_value)
            output.close()
         
        delblankline("config.conf","config2.conf")
        #布局
        self.gridlayout = QtGui.QGridLayout()
         
         
        #设置出20 x 20 的格局
        for i in range(20):
            self.gridlayout.setColumnStretch(i,1)
            self.gridlayout.setRowStretch(i,1)
         
         
         
         
         
        lb1 = QLabel(u'平台：')
        self.gridlayout.addWidget(lb1, 0, 0,1,6)
#         #hosts文本框
        self.servernameEntry = QComboBox()
#         self.posEntry.setText(posvalue)
        self.gridlayout.addWidget(self.servernameEntry, 0, 4,1,9)
#         for i in range(0,11):
#             if str(posvalue) != str(i):
        servers = [u'aoshitang',u'37',u'7477']
        self.servernameEntry.addItem(str(servername_value))
        for serverss in servers:
            if str(servername_value) <> str(serverss):
                self.servernameEntry.addItem(str(serverss))
         
        #选择第几个角色
        lbjuese = QLabel(u'选择第几个角色：')
        self.gridlayout.addWidget(lbjuese, 0, 13,1,13)
        self.playersEntry = QComboBox()
        self.gridlayout.addWidget(self.playersEntry, 0, 25,1,5)
        self.playersEntry.addItem(u'1')
        self.playersEntry.addItem(u'2')
        self.playersEntry.addItem(u'3')
         
        self.ifFenbinEntry = QCheckBox(u'选择是否远征分兵突袭')
        self.ifFenbinEntry.setPalette(pe)  
        if ifFenbin_value is not None:
            if str(ifFenbin_value) == '1':
                self.ifFenbinEntry.setChecked(True)
            else:
                self.ifFenbinEntry.setChecked(False)
        else:
            self.ifFenbinEntry.setChecked(False)
        self.gridlayout.addWidget(self.ifFenbinEntry, 0, 35,1,25)
        
        
        lb2 = QLabel(u'区服：')
        self.gridlayout.addWidget(lb2, 1, 0,1,4)
        #root文本框
        self.serveridEntry = QLineEdit()
        re1=QtCore.QRegExp('[0-9+()*/%//=-]*')
        self.serveridEntry.setValidator(QtGui.QRegExpValidator(re1,self))
        self.serveridEntry.setText(str(serverid_value))
        self.gridlayout.addWidget(self.serveridEntry, 1, 4,1,4)
         
        lbusernames = QLabel(u'用户登陆名')
        self.gridlayout.addWidget(lbusernames, 1, 8,1,9)
        lbusernames.setPalette(pe)  
        #root文本框
        self.lbusernamessEntry = QLineEdit()
        self.lbusernamessEntry.setText(usernames_value.decode("utf-8"))
        self.gridlayout.addWidget(self.lbusernamessEntry, 1, 16,1,10)
        lbusernamesintro = QLabel(u'用于多号选角cookies区分，\n不填默认读最近可用cookies')
        self.gridlayout.addWidget(lbusernamesintro, 1, 26,1,20)
         
        lbjiuguan1 = QLabel(u'酒馆投资位：')
        self.gridlayout.addWidget(lbjiuguan1, 2, 0,1,14)
        lbjiuguan1.setPalette(pe)  
        lbjiuguan1.setToolTip(u"用于贿赂红将，1-10,其他数字为不贿赂")
        #酒馆下拉框
        pos = 8
        for i in range(len(posvalue)):
            self.BL['pos%s' % i] = QComboBox()
            self.gridlayout.addWidget(self.BL['pos%s' % i], 2, pos,1,5)
#             print posvalue[i]
            self.BL['pos%s' % i].addItem(str(posvalue[i]))
            for j in range(0,11):
                if str(posvalue[i]) != str(j):
                    self.BL['pos%s' % i].addItem(str(j))
                self.BL['pos%s' % i].setToolTip(u"用于贿赂红将，1-10,其他数字为不贿赂")
            pos = pos +5
                 
#         lbjiuguan2  = QLabel(u'酒馆投资位2：')
#         self.gridlayout.addWidget(lbjiuguan2, 2, 12,1,13)
#         lbjiuguan2.setPalette(pe)  
#         lbjiuguan2.setToolTip(u"用于贿赂红将，1-10,其他数字为不贿赂")
#         #酒馆下拉框
#         self.posEntry = QComboBox()
#         self.gridlayout.addWidget(self.posEntry, 2, 19,1,5)
#         self.posEntry.addItem(posvalue)
#         for i in range(0,11):
#             if str(posvalue) != str(i):
#                 self.posEntry.addItem(str(i))
#         self.posEntry.setToolTip(u"用于贿赂红将，1-10,其他数字为不贿赂")
         
         
         
        lb20 = QLabel(u'国防建设：')
        self.gridlayout.addWidget(lb20, 2, 33,1,8)
        lb20.setToolTip(u"1. 初级大理石：10分钟30大理石\
                                    \n2. 中级大理石：30分钟120大理石\
                                    \n3. 高级大理石：60分钟240大理石\
                                    \n4. 初级谎报：10分钟谎报1，减少守军熟练\
                                    \n5. 中级谎报：30分钟谎报1，减少守军熟练\
                                    \n6. 高级谎报：60分钟谎报1，减少守军熟练\
                                    \n7. 初级级炸弹：20分钟耗粮10000，炸弹1、经验5W，减少城墙血量\
                                    \n8. 中级级炸弹：20分钟耗粮15000，炸弹1、经验7.5W，减少城墙血量\
                                    \n9. 高级炸弹：20分钟耗粮20000，炸弹1、经验10W，减少城墙血量\
                                    \n10. 初级内讧：20分钟耗粮30000，内讧1、经验15W，减少守军数量\
                                    \n11. 中级内讧：20分钟耗粮40000，内讧1、经验20W，减少守军数量\
                                    \n12. 高级内讧：20分钟耗粮50000，内讧1、经验25W，减少守军数量")
        self.guofangEntry = QComboBox()
        self.gridlayout.addWidget(self.guofangEntry, 2, 40,1,6)
        self.guofangEntry.addItem(guofang_value)
        for i in range(1,13):
            if str(guofang_value) != str(i):
                self.guofangEntry.addItem(str(i))
        self.guofangEntry.setToolTip(u"1. 初级大理石：10分钟30大理石\
                                    \n2. 中级大理石：30分钟120大理石\
                                    \n3. 高级大理石：60分钟240大理石\
                                    \n4. 初级谎报：10分钟谎报1，减少守军熟练\
                                    \n5. 中级谎报：30分钟谎报1，减少守军熟练\
                                    \n6. 高级谎报：60分钟谎报1，减少守军熟练\
                                    \n7. 初级级炸弹：20分钟耗粮10000，炸弹1、经验5W，减少城墙血量\
                                    \n8. 中级级炸弹：20分钟耗粮15000，炸弹1、经验7.5W，减少城墙血量\
                                    \n9. 高级炸弹：20分钟耗粮20000，炸弹1、经验10W，减少城墙血量\
                                    \n10. 初级内讧：20分钟耗粮30000，内讧1、经验15W，减少守军数量\
                                    \n11. 中级内讧：20分钟耗粮40000，内讧1、经验20W，减少守军数量\
                                    \n12. 高级内讧：20分钟耗粮50000，内讧1、经验25W，减少守军数量")
         
#         lb6 = QLabel(u'升级武将')
#         self.gridlayout.addWidget(lb6, 3, 0,1,4)
#         lb6.setToolTip(u"请填写武将id，不填表示不升级")
#         #升级武将文本框
#         self.upgradeBaowuEntry = QLineEdit()
#         self.upgradeBaowuEntry.setValidator(QtGui.QRegExpValidator(re1,self))
#         self.gridlayout.addWidget(self.upgradeBaowuEntry, 3, 4,1,3)
#         self.upgradeBaowuEntry.setText(upgradeBaowu_value)
#         
#         self.upgradeBaowuEntry.setToolTip(u"请填写武将id，不填表示不升级")
         
        #是否大远征
#         self.ifbigEntry = QCheckBox(u'是否大远征')
#         if ifbig_value is not None:
#             if str(ifbig_value) == '1':
#                 self.ifbigEntry.setChecked(True)
#         else:
#             self.ifbigEntry.setChecked(False)
#         self.gridlayout.addWidget(self.ifbigEntry, 3, 5,1,8)
#         
#         #是否1v2
#         self.if1v2Entry = QCheckBox(u'是否1v2')
#         if if1v2_value is not None:
#             if str(if1v2_value) == '1':
#                 self.if1v2Entry.setChecked(True)
#         else:
#             self.if1v2Entry.setChecked(False)
#         self.gridlayout.addWidget(self.if1v2Entry, 3, 9,1,8)
         
#         self.bingfaEntry = QLineEdit()
#         lb12 = QLabel(u'兵法id')
#         self.gridlayout.addWidget(lb12, 2, 17,1,13)
#         #兵法文本框
#         self.bingfaEntry = QLineEdit()
#         re1=QtCore.QRegExp('[0-9+()*/%//=-]*')
#         self.bingfaEntry.setValidator(QtGui.QRegExpValidator(re1,self))
#         self.bingfaEntry.setText(bingfa_value)
#         self.gridlayout.addWidget(self.bingfaEntry, 2, 21,1,2) 
#         self.bingfaEntry.setToolTip(u"兵法Id自行截取或询问获得")
         
         
         
         
        #下方为建筑升级
        lbcc = QLabel(u'升级建筑：')
        self.gridlayout.addWidget(lbcc, 3, 0,1,13)
        if not isinstance(citybuilding_value, list):
            citybuilding_value = eval(citybuilding_value)
        #建筑复选框1    
        pos = 7
        for i in range(7):
#             if i == 0:
#                 pos = 7
#             else:
#                 pos = i*6+6
            self.BL['citybuilding%s' % i]  = QCheckBox(cityDict[str(citybuilding_lists[i])])
            if citybuilding_lists[i] in citybuilding_value: 
                self.BL['citybuilding%s' % i].setChecked(True)
            else:
                self.BL['citybuilding%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['citybuilding%s' % i], 3, pos,1,7)
            self.BL['citybuilding%s' % i].setToolTip(cityDict[str(citybuilding_lists[i])])
            pos = pos+8
        #建筑复选框2
        pos = 7
        for i in range(7,len(citybuilding_lists)):
#             pos = i -6
            self.BL['citybuilding%s' % i]  = QCheckBox(cityDict[str(citybuilding_lists[i])])
            if citybuilding_lists[i] in citybuilding_value: 
                self.BL['citybuilding%s' % i].setChecked(True)
            else:
                self.BL['citybuilding%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['citybuilding%s' % i], 4, pos,1,9)
            self.BL['citybuilding%s' % i].setToolTip(cityDict[str(citybuilding_lists[i])])
            pos = pos+8
         
#         #宝石文官事件选择按钮
#         self.eventGemEntry = QCheckBox(u'宝石文官事件(消耗金币)')
#         if eventGem_value is not None:
#             if str(eventGem_value) == '1':
#                 self.eventGemEntry.setChecked(True)
#             else:
#                 self.eventGemEntry.setChecked(False)
#         else:
#             self.eventGemEntry.setChecked(False)
#         self.gridlayout.addWidget(self.eventGemEntry, 5, 0,1,10)
         
        self.firesEntry = QCheckBox(u'烧火（远征后消耗金币获得兵书）')
        if fires_value is not None:
            if str(fires_value) == '1':
                self.firesEntry.setChecked(True)
            else:
                self.firesEntry.setChecked(False)
        else:
            self.firesEntry.setChecked(False)
        self.gridlayout.addWidget(self.firesEntry, 2, 46,1,25)
         
         
         
         
        #三顾茅庐是否升级按钮
        self.threeEntry = QCheckBox(u'免费三顾茅庐(兵书版)\n(勾选后最优方案\n花费金币升级)')
        if three_value is not None:
            if str(three_value) == '1':
                self.threeEntry.setChecked(True)
            else:
                self.threeEntry.setChecked(False)
        else:
            self.threeEntry.setChecked(False)
        self.gridlayout.addWidget(self.threeEntry, 5, 22,1,17)
        threesss = [0]
        for i in range(20,100):
            if i%5 == 0:
                threesss.append(i)
        #三顾买至显示金币
        self.threeGoldEntry = QComboBox()
        self.gridlayout.addWidget(self.threeGoldEntry, 5, 38,1,6)
        self.threeGoldEntry.addItem(str(threeGold_value))
        self.threeGoldEntry.setToolTip(u"寻访显示金币停止")
        for yuansu in threesss:
            if str(yuansu) <> str(threeGold_value):
                self.threeGoldEntry.addItem(str(yuansu))
         
        #三顾茅庐是否升级按钮
        self.threeEntry2 = QCheckBox(u'免费三顾茅庐(宝石版)\n(勾选后最优方案\n花费金币升级)')
        if three_value2 is not None:
            if str(three_value2) == '1':
                self.threeEntry2.setChecked(True)
            else:
                self.threeEntry2.setChecked(False)
        else:
            self.threeEntry2.setChecked(False)
        self.gridlayout.addWidget(self.threeEntry2, 5, 44,1,17)
         
        #三顾买至显示金币
        self.threeGoldEntry2 = QComboBox()
        self.gridlayout.addWidget(self.threeGoldEntry2, 5, 59,1,6)
        self.threeGoldEntry2.addItem(str(threeGold2_value))
        self.threeGoldEntry2.setToolTip(u"寻访显示金币停止")
        for yuansu in threesss:
            if str(yuansu) <> str(threeGold2_value):
                self.threeGoldEntry2.addItem(str(yuansu))
                 
        #银币转盘买至显示金币
        lbcc1 = QLabel(u'银币转盘消耗至显示金币：')
        self.gridlayout.addWidget(lbcc1, 1, 46,1,17)
        lbcc1.setPalette(pe)  
         
        self.yinbizhuanpanGoldEntry = QComboBox()
        self.gridlayout.addWidget(self.yinbizhuanpanGoldEntry, 1, 63,1,6)
        self.yinbizhuanpanGoldEntry.addItem(str(yinbizhuanpanGold_value))
        self.yinbizhuanpanGoldEntry.setToolTip(u"寻访显示金币停止")
        for yuansu in threesss:
            if str(yuansu) <> str(yinbizhuanpanGold_value):
                self.yinbizhuanpanGoldEntry.addItem(str(yuansu))
        #捞宝物买至显示金币
        lbcclao = QLabel(u'捞宝物消耗至显示金币：')
        self.gridlayout.addWidget(lbcclao, 0, 53,1,17)
        lbcclao.setPalette(pe)  
         
        self.laobaowuGoldEntry = QComboBox()
        self.gridlayout.addWidget(self.laobaowuGoldEntry, 0, 68,1,6)
        self.laobaowuGoldEntry.addItem(str(laobaowuGold_value))
        self.laobaowuGoldEntry.setToolTip(u"寻访显示金币停止")
        for yuansu in threesss:
            if str(yuansu) <> str(laobaowuGold_value):
                self.laobaowuGoldEntry.addItem(str(yuansu))
         
        #是否宝物升级忠诚度
        self.zhongchengEntry = QCheckBox(u'是否宝物升级忠诚度')
        if zhongcheng_vallue is not None:
            if str(zhongcheng_vallue) == '1':
                self.zhongchengEntry.setChecked(True)
            else:
                self.zhongchengEntry.setChecked(False)
        else:
            self.zhongchengEntry.setChecked(False)
             
        self.gridlayout.addWidget(self.zhongchengEntry, 5, 66,1,17)
        self.zhongchengEntry.setPalette(pe)  
         
         
         
        self.gridlayout.addWidget(QLabel(u'远征排除玩家名\n玩家名英文分号\n分隔例如：\n玩家1;玩家2'), 5, 0,1,12)
        self.exceptEntry = QTextEdit()
        self.exceptEntry.setText(except_value.decode("utf-8"))
        self.gridlayout.addWidget(self.exceptEntry, 5, 11, 1, 10)
         
         
        #下方为城战类型
        lb10 = QLabel(u'选择国战类型：')
        self.gridlayout.addWidget(lb10, 6, 0,1,13)
        lb10.setPalette(pe)  
        #普通
        self.CheckPutongEntry = QCheckBox(u'普通')
        if CheckPutong_value is not None:
            if str(CheckPutong_value) == '1':
                self.CheckPutongEntry.setChecked(True)
            else:
                self.CheckPutongEntry.setChecked(False)
        else:
            self.CheckPutongEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckPutongEntry, 6, 9,1,6)
        #关卡
        self.CheckGuankaEntry = QCheckBox(u'关卡')
        if CheckGuanka_value is not None:
            if str(CheckGuanka_value) == '1':
                self.CheckGuankaEntry.setChecked(True)
            else:
                self.CheckGuankaEntry.setChecked(False)
        else:
            self.CheckGuankaEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckGuankaEntry, 6, 15,1,7)
        #滚石
        self.CheckGunshiEntry = QCheckBox(u'滚石')
        if CheckGunshi_value is not None:
            if str(CheckGunshi_value) == '1':
                self.CheckGunshiEntry.setChecked(True)
            else:
                self.CheckGunshiEntry.setChecked(False)
        else:
            self.CheckGunshiEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckGunshiEntry, 6, 21,1,6)
        #森林
        self.CheckSenlinEntry = QCheckBox(u'森林')
        if CheckSenlin_value is not None:
            if str(CheckSenlin_value) == '1':
                self.CheckSenlinEntry.setChecked(True)
            else:
                self.CheckSenlinEntry.setChecked(False)
        else:
            self.CheckSenlinEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckSenlinEntry, 6, 27,1,6)
        #草原
        self.CheckCaoyuanEntry = QCheckBox(u'草原')
        if CheckCaoyuan_value is not None:
            if str(CheckCaoyuan_value) == '1':
                self.CheckCaoyuanEntry.setChecked(True)
            else:
                self.CheckCaoyuanEntry.setChecked(False)
        else:
            self.CheckCaoyuanEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckCaoyuanEntry, 6, 33,1,6)
        #水域
        self.CheckShuiyuEntry = QCheckBox(u'水域')
        if CheckShuiyu_value is not None:
            if str(CheckShuiyu_value) == '1':
                self.CheckShuiyuEntry.setChecked(True)
            else:
                self.CheckShuiyuEntry.setChecked(False)
        else:
            self.CheckShuiyuEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckShuiyuEntry, 6, 39,1,6)
        #护城河
        self.CheckHuchengheEntry = QCheckBox(u'护城河')
        if CheckHuchenghe_value is not None:
            if str(CheckHuchenghe_value) == '1':
                self.CheckHuchengheEntry.setChecked(True)
            else:
                self.CheckHuchengheEntry.setChecked(False)
        else:
            self.CheckHuchengheEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckHuchengheEntry, 6, 45,1,8)
        #蛮族城
        self.CheckManzuchengEntry = QCheckBox(u'蛮族城')
        if CheckManzucheng_value is not None:
            if str(CheckManzucheng_value) == '1':
                self.CheckManzuchengEntry.setChecked(True)
            else:
                self.CheckManzuchengEntry.setChecked(False)
        else:
            self.CheckManzuchengEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckManzuchengEntry, 6, 52,1,8)
        #峡谷
        self.CheckXiaguEntry = QCheckBox(u'峡谷')
        if CheckXiagu_value is not None:
            if str(CheckXiagu_value) == '1':
                self.CheckXiaguEntry.setChecked(True)
            else:
                self.CheckXiaguEntry.setChecked(False)
        else:
            self.CheckXiaguEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckXiaguEntry, 6, 59,1,6)
        #港口
        self.CheckGangkouEntry = QCheckBox(u'港口')
        if CheckGangkou_value is not None:
            if str(CheckGangkou_value) == '1':
                self.CheckGangkouEntry.setChecked(True)
            else:
                self.CheckGangkouEntry.setChecked(False)
        else:
            self.CheckGangkouEntry.setChecked(False)
        self.gridlayout.addWidget(self.CheckGangkouEntry, 6, 65,1,6)
         
         
        if not isinstance(wenguans_value, list):
            wenguans_value = eval(wenguans_value)
        #下方为文官事件类型
        lbaa = QLabel(u'文官事件类型：')
        self.gridlayout.addWidget(lbaa, 7, 0,1,25)
         
        lbaa.setPalette(pe)  
        lbaa = QLabel(u'（募兵、新军务为默认）')
        self.gridlayout.addWidget(lbaa, 7, 57,1,25)
        self.wenguans_value = wenguans_value
        pos = 9
        for i in range(len(wenguans_value)):
            if  i == 0:
                names = u'进修'
                self.wenguan0 = QCheckBox(names)
            elif i == 1:
                names = u'修城'
                self.wenguan1 = QCheckBox(names)
            elif i == 2:
                names = u'收税'
                self.wenguan2 = QCheckBox(names)
            elif i == 3:
                names = u'屯田'
                self.wenguan3 = QCheckBox(names)
            elif i == 4:
                names = u'召民工'
                self.wenguan4 = QCheckBox(names)
            elif i == 5:
                names = u'采矿'
                self.wenguan5 = QCheckBox(names)
            elif i == 6:
                names = u'宝石商'
                self.wenguan6 = QCheckBox(names)
                self.wenguan6.setPalette(pe)  
                self.wenguan6.setToolTip(u"花金币的哦")
            elif i == 7:
                names = u'卖粮'
                self.wenguan7 = QCheckBox(names)
                self.wenguan7.setPalette(pe)  
                self.wenguan7.setToolTip(u"花金币的哦")
            self.wenguanInt(wenguans_value[i],"wenguan%s"%i,pos)
            pos = pos + 6
             
        #下方为武将升级
        lbbb = QLabel(u'下方为武将升级(忠诚度为阵上武将默认升级)')
        self.gridlayout.addWidget(lbbb, 8, 0,1,31)
        lbbb.setPalette(pe)  
        if not isinstance(qilist_value, list):
            qilist_value = eval(qilist_value)
        if not isinstance(gonglist_value, list):
            gonglist_value = eval(gonglist_value)
        if not isinstance(bulist_value, list):
            bulist_value = eval(bulist_value)
        if not isinstance(chelist_value, list):
            chelist_value = eval(chelist_value)
         
        #车兵创建复选框    
        pos = 31
        for i in range(len(che_lists)):
            self.BL['c%s' % i]  = QCheckBox(che_lists[i])
            if ini_generals[str(che_lists[i])] in chelist_value:
                self.BL['c%s' % i].setChecked(True)
            else:
                self.BL['c%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['c%s' % i], 8, pos,1,6)
            self.BL['c%s' % i].setToolTip(che_lists[i])
            pos = pos + 6
        
        self.ifyongjiu  = QCheckBox(u"是否永久下方选中武将")
        self.ifyongjiu.setPalette(pe)
        self.ifyongjiu.setFont(QFont("Roman times",10,QFont.Bold))
        if ifyongjiu_value == "1":
            self.ifyongjiu.setChecked(True)
        else:
            self.ifyongjiu.setChecked(False)
        self.gridlayout.addWidget(self.ifyongjiu, 8, pos,1,22)
        
        #骑兵创建复选框    
        pos = 1
        for i in range(len(qi_lists)):
            self.BL['q%s' % i]  = QCheckBox(qi_lists[i])
            if ini_generals[str(qi_lists[i])] in qilist_value:
                self.BL['q%s' % i].setChecked(True)
            else:
                self.BL['q%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['q%s' % i], 9, pos,1,8)
            self.BL['q%s' % i].setToolTip(qi_lists[i])
            pos = pos +7
        #弓兵创建复选框    
        pos = 1
        for i in range(len(gong_lists)):
            self.BL['g%s' % i]  = QCheckBox(gong_lists[i])
            if ini_generals[str(gong_lists[i])] in gonglist_value:
                self.BL['g%s' % i].setChecked(True)
            else:
                self.BL['g%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['g%s' % i], 10, pos,1,8)
            self.BL['g%s' % i].setToolTip(gong_lists[i])
            pos = pos +7
        #步兵创建复选框    
        pos = 1
        for i in range(len(bu_lists)):
            self.BL['b%s' % i]  = QCheckBox(bu_lists[i])
            if ini_generals[str(bu_lists[i])] in bulist_value:
                self.BL['b%s' % i].setChecked(True)
            else:
                self.BL['b%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['b%s' % i], 11, pos,1,8)
            self.BL['b%s' % i].setToolTip(bu_lists[i])
            pos = pos +7
        #下方为兵法升级
        if not isinstance(bingfas_value, list):
            bingfas_value = eval(bingfas_value)
        #建筑复选框1    
        bu_zhanfa = [2,6,7,12,13,19,23,29]
        qi_zhanfa = [3,8,9,14,15,20,24,30]
        gong_zhanfa = [4,10,11,16,17,21,25,31]
        che_zhanfa = [1,5,18,22,26,27,28,32]
        lbcc = QLabel(u'步兵战法升级：')
        self.gridlayout.addWidget(lbcc, 12, 0,1,13)
        lbcc.setPalette(pe)
        pos = 9
        for i in range(len(bingfa_lists)):
            if bingfa_lists[i] in bu_zhanfa:
                self.BL['zhanfa%s' % i]  = QCheckBox(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] in bingfas_value: 
                    self.BL['zhanfa%s' % i].setChecked(True)
                else:
                    self.BL['zhanfa%s' % i].setChecked(False)
                self.gridlayout.addWidget(self.BL['zhanfa%s' % i], 12, pos,1,9)
                self.BL['zhanfa%s' % i].setToolTip(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] > 28 and bingfa_lists[i] < 33:
                    self.BL['zhanfa%s' % i].setPalette(pe)
                pos = pos+9
        lbcc = QLabel(u'骑兵战法升级：')
        self.gridlayout.addWidget(lbcc, 13, 0,1,13)
#         lbcc.setFont(QFont("Roman times",10,QFont.Bold))  
         
#         self.label.setAutoFillBackground(True)#设置背景充满，为设置背景颜色的必要条件  
#         pe.setColor(QPalette.Window,Qt.blue)#设置背景颜色  
        #pe.setColor(QPalette.Background,Qt.blue)<span style="font-family: Arial, Helvetica, sans-serif;">#设置背景颜色，和上面一行的效果一样  
        lbcc.setPalette(pe)
        pos = 9
        for i in range(len(bingfa_lists)):
            if bingfa_lists[i] in qi_zhanfa:
                self.BL['zhanfa%s' % i]  = QCheckBox(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] in bingfas_value: 
                    self.BL['zhanfa%s' % i].setChecked(True)
                else:
                    self.BL['zhanfa%s' % i].setChecked(False)
                self.gridlayout.addWidget(self.BL['zhanfa%s' % i], 13, pos,1,9)
                self.BL['zhanfa%s' % i].setToolTip(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] > 28 and bingfa_lists[i] < 33:
                    self.BL['zhanfa%s' % i].setPalette(pe)
                pos = pos+9
        lbcc = QLabel(u'弓兵战法升级：')
        self.gridlayout.addWidget(lbcc, 14, 0,1,13)
        lbcc.setPalette(pe)
        pos = 9
        for i in range(len(bingfa_lists)):
            if bingfa_lists[i] in gong_zhanfa:
                self.BL['zhanfa%s' % i]  = QCheckBox(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] in bingfas_value: 
                    self.BL['zhanfa%s' % i].setChecked(True)
                else:
                    self.BL['zhanfa%s' % i].setChecked(False)
                self.gridlayout.addWidget(self.BL['zhanfa%s' % i], 14, pos,1,9)
                self.BL['zhanfa%s' % i].setToolTip(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] > 28 and bingfa_lists[i] < 33:
                    self.BL['zhanfa%s' % i].setPalette(pe)
                pos = pos+9
        lbcc = QLabel(u'车及双系战法：')
        self.gridlayout.addWidget(lbcc, 15, 0,1,13)
        lbcc.setPalette(pe)
        pos = 9
        for i in range(len(bingfa_lists)):
            if bingfa_lists[i] in che_zhanfa:
                self.BL['zhanfa%s' % i]  = QCheckBox(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] in bingfas_value: 
                    self.BL['zhanfa%s' % i].setChecked(True)
                else:
                    self.BL['zhanfa%s' % i].setChecked(False)
                self.gridlayout.addWidget(self.BL['zhanfa%s' % i], 15, pos,1,9)
                self.BL['zhanfa%s' % i].setToolTip(bingfaDict[str(bingfa_lists[i])])
                if bingfa_lists[i] > 28 and bingfa_lists[i] < 33:
                    self.BL['zhanfa%s' % i].setPalette(pe)
                pos = pos+9
        lbcc = QLabel(u'主公宝物升级：')
        self.gridlayout.addWidget(lbcc, 16, 0,1,13)
        lbcc.setPalette(pe)
        pos = 9
        for i in range(len(zhugongbaowu_value)):
#             if zhugongbaowu_value[i] in che_zhanfa:
            self.BL['zhugongbaowu%s' % i]  = QCheckBox(u"位置%s"%(i+1))
            if str(zhugongbaowu_value[i]) == '1': 
                self.BL['zhugongbaowu%s' % i].setChecked(True)
            else:
                self.BL['zhugongbaowu%s' % i].setChecked(False)
            self.gridlayout.addWidget(self.BL['zhugongbaowu%s' % i], 16, pos,1,9)
#                 self.BL['zhugongbaowu%s' % i].setToolTip(bingfaDict[str(zhugongbaowu_value[i])])
            pos = pos+9
         
         
         
        #开始挂机按钮
        self.loginBtn = QtGui.QPushButton(u"开始挂机")
        self.loginBtn.setFixedSize(80,20)
        self.loginBtn.setToolTip(u"日志每轮都会清理")
        setCache("loginBtn", self.loginBtn)
        self.connect(self.loginBtn, QtCore.SIGNAL('clicked()'), self.onLoginButton)
        self.gridlayout.addWidget(self.loginBtn, 16, 3,8,2)
         
         
        #停止操作按钮
        self.stopBtn = QtGui.QPushButton(u"停止操作")
        self.stopBtn.setFixedSize(80,20)
        setCache("stopBtn", self.stopBtn)
        self.connect(self.stopBtn, QtCore.SIGNAL('clicked()'), self.onStopButton)
        self.gridlayout.addWidget(self.stopBtn, 16, 15,8,2)
         
        getCache('stopBtn').setEnabled(False)
         
        #清空日志按钮
        self.clearlogBtn = QtGui.QPushButton(u"清空日志")
        self.clearlogBtn.setFixedSize(80,20)
        setCache("clearlogBtn", self.clearlogBtn)
        self.connect(self.clearlogBtn, QtCore.SIGNAL('clicked()'), self.onClearlogButton)
        self.gridlayout.addWidget(self.clearlogBtn, 16, 27,8,2)
        self.setLayout(self.gridlayout)   
         
         
        lb9 = QLabel(u'使用方法：请先点击开始挂机，然后浏览器中重新进入游戏，\n如若掉线，可能需要反复几次重新进入游戏')
        self.gridlayout.addWidget(lb9, 22, 0,1,40)
     
     
        lbx = QLabel(u'最完美解决反复掉线方法：\n1. 删除目录下cookies下文件\n2. 浏览器至选角色界面\n3. 开始挂机\n4. 选角进入游戏')
        self.gridlayout.addWidget(lbx, 22, 39,1,33)
        lbx.setPalette(pe)  
        lbx.setFont(QFont("Roman times",10,QFont.Bold))
        
    def wenguanInt(self,wenguansss,names,pos):
#         if pos <> 0:
#             pos = pos*5 + 10
#         else:
#             pos = 10
            
        if wenguansss == 1:
            eval("self.%s.setChecked(True)"%names)
        else:
            eval("self.%s.setChecked(False)"%names)
        eval("self.gridlayout.addWidget(self.%s, 7, %s,1,7)"%(names,pos))
    #print输出内容
    def normalOutputWritten(self, text):
        """Append text to the QTextEdit."""
        # Maybe QTextEdit.append() works as well, but this is how I do it:
        cursor = self.tab2.textCursor()
        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertText(text)
        self.tab2.setTextCursor(cursor)
        self.tab2.ensureCursorVisible()
    
    #响应登录按钮
    def onLoginButton(self):
        delLog()
        
        #清空各种dict
        deleteCache('hosts')
        deleteCache('players')
        deleteCache('root')
        deleteCache('cookiesss')
        deleteCache('playerheaders')
        deleteCache('servername')
        deleteCache('lbusernamess')
        deleteCache('playerName')
        deleteCache('force_id')
        deleteCache('playerLvs')
        deleteCache('player_id')
        deleteCache('dbId')
        deleteCache('pos')
        deleteCache('guofang')
        deleteCache('fires')
#         deleteCache('bingfa')
#         deleteCache('upgradeBaowu')
        deleteCache('generalIds')
        deleteCache('exceptss')
        deleteCache('brawlsState')
        deleteCache('three')
        deleteCache('CheckedWenguan')
        deleteCache('qianghua_bingzhong')
        deleteCache('cityUpgrade')
        deleteCache('upgradeBingfas')
        deleteCache('zhugongbaowu')
        deleteCache('zhongchengdu')
        deleteCache('threeGold')
        deleteCache('threeGold2')
        deleteCache('yinbizhuanpanGold')
        deleteCache('laobaowuGold')
        deleteCache('ifFenbin')
        deleteCache("ifyongjiu")
        setCache("expBuild", [])
        
        
        #三顾茅庐（兵书版）显示金币
        threeGold = self.threeGoldEntry.currentText()
        #三顾茅庐（宝石版）显示金币
        threeGold2 = self.threeGoldEntry2.currentText()
        setCache('threeGold', threeGold)
        setCache('threeGold2', threeGold2)
        setConfig('threeGold', str(threeGold))
        setConfig('threeGold2', str(threeGold2))
        
        yinbizhuanpanGold = self.yinbizhuanpanGoldEntry.currentText()
        setCache('yinbizhuanpanGold', yinbizhuanpanGold)
        setConfig('yinbizhuanpanGold', str(yinbizhuanpanGold))
        
        laobaowuGold = self.laobaowuGoldEntry.currentText()
        setCache('laobaowuGold', laobaowuGold)
        setConfig('laobaowuGold', str(laobaowuGold))
        
        
        servername = self.servernameEntry.currentText()
        setConfig('servername', str(servername))
        players = self.playersEntry.currentText()
        serverid = self.serveridEntry.text()
        
        setConfig('serverid', serverid)
        
        excepts = str(self.exceptEntry.toPlainText())
            
        exceptss = excepts.split(";")
        
        lbusernamess = self.lbusernamessEntry.text()
        
        setCache('lbusernamess', str(lbusernamess))
        setCache('servername', str(servername))
        if str(servername) == 'aoshitang':
            hosts = 's%s.ls.aoshitang.com' % serverid
            root = 'http://s%s.ls.aoshitang.com/root/gateway.action' % serverid
        elif str(servername) == '37':
            hosts = 's%s.tqcf.37.com' % serverid
            root = 'http://s%s.tqcf.37.com/root/gateway.action' % serverid
        elif str(servername) == '7477':
            hosts = 's%s.tqcf.7477.com' % serverid
            root = 'http://s%s.tqcf.7477.com/root/gateway.action' % serverid

#         pos = self.posEntry.currentText()
        
        pos = []
        for i in range(len(pos_ini)):
            pos.append(str(self.BL['pos%s' % i].currentText()))
            
        guofang = self.guofangEntry.currentText()
#         #升级武将的id        
#         upgradeBaowu = self.upgradeBaowuEntry.text()
        
#         bingfa= self.bingfaEntry.text()
        
        if self.firesEntry.isChecked():
            fires = '1'
        else:
            fires = '0'
        if self.ifFenbinEntry.isChecked():
            ifFenbin = '1'
        else:
            ifFenbin = '0'
        setCache('ifFenbin', ifFenbin)
        setConfig('ifFenbin', ifFenbin)
            
        if self.ifyongjiu.isChecked():
            ifyongjius = '1'
        else:
            ifyongjius = '0'
        setCache('ifyongjiu', ifyongjius)
        setConfig('ifyongjiu', ifyongjius)
        
        
        
        
        CheckedCityType = []
        if self.CheckPutongEntry.isChecked():
            CheckedCityType.append(-1)
            CheckPutong = '1'
        else:
            CheckPutong = '0'
        if self.CheckGuankaEntry.isChecked():
            CheckedCityType.append(0)
            CheckGuanka = '1'
        else:
            CheckGuanka = '0'
        if self.CheckGunshiEntry.isChecked():
            CheckedCityType.append(2)
            CheckGunshi = '1'
        else:
            CheckGunshi = '0'
        if self.CheckSenlinEntry.isChecked():
            CheckedCityType.append(3)
            CheckSenlin = '1'
        else:
            CheckSenlin = '0'
        if self.CheckCaoyuanEntry.isChecked():
            CheckedCityType.append(4)
            CheckCaoyuan = '1'
        else:
            CheckCaoyuan = '0'
        if self.CheckShuiyuEntry.isChecked():
            CheckedCityType.append(5)
            CheckShuiyu = '1'
        else:
            CheckShuiyu = '0'
        if self.CheckHuchengheEntry.isChecked():
            CheckedCityType.append(6)
            CheckHuchenghe = '1'
        else:
            CheckHuchenghe = '0'
        if self.CheckManzuchengEntry.isChecked():
            CheckedCityType.append(7)
            CheckManzucheng = '1'
        else:
            CheckManzucheng = '0'
        if self.CheckXiaguEntry.isChecked():
            CheckedCityType.append(8)
            CheckXiagu = '1'
        else:
            CheckXiagu = '0'
        if self.CheckGangkouEntry.isChecked():
            CheckedCityType.append(9)
            CheckGangkou = '1'
        else:
            CheckGangkou = '0'
        setCache('CheckedCityType', CheckedCityType)
        
        CheckedWenguan = []
        #新军务
        CheckedWenguan.append(5)
        if self.wenguan0.isChecked():
            CheckedWenguan.append(1)
            CheckedWenguan.append(2)
            self.wenguans_value[0]=1
        else:
            self.wenguans_value[0]=0
        if self.wenguan1.isChecked():
            CheckedWenguan.append(3)
            self.wenguans_value[1]=1
        else:
            self.wenguans_value[1]=0
        if self.wenguan2.isChecked():
            CheckedWenguan.append(6)
            self.wenguans_value[2]=1
        else:
            self.wenguans_value[2]=0
        if self.wenguan3.isChecked():
            CheckedWenguan.append(7)
            CheckedWenguan.append(8)
            CheckedWenguan.append(9)
            self.wenguans_value[3]=1
        else:
            self.wenguans_value[3]=0
        if self.wenguan4.isChecked():
            CheckedWenguan.append(10)
            self.wenguans_value[4]=1
        else:
            self.wenguans_value[4]=0
        if self.wenguan5.isChecked():
            CheckedWenguan.append(11)
            self.wenguans_value[5]=1
        else:
            self.wenguans_value[5]=0
        if self.wenguan6.isChecked():
            CheckedWenguan.append(15)
            self.wenguans_value[6]=1
        else:
            self.wenguans_value[6]=0
        if self.wenguan7.isChecked():
            CheckedWenguan.append(14)
            self.wenguans_value[7]=1
        else:
            self.wenguans_value[7]=0
        #文官事件
        setCache('CheckedWenguan', CheckedWenguan)
        setConfig('wenguans', str(self.wenguans_value))
        
        qianghua_bingzhong = []
        #确定骑兵投资目标
        touzi_qibing = []
        for i in range(len(qi_lists)):
            if self.BL['q%s' % i].isChecked():
                touzi_qibing.append(ini_generals[str(qi_lists[i])])
        
        setConfig('qilist', str(touzi_qibing))
        #确定弓兵投资目标
        touzi_gongbing = []
        for i in range(len(gong_lists)):
            if self.BL['g%s' % i].isChecked():
                touzi_gongbing.append(ini_generals[str(gong_lists[i])])
        setConfig('gonglist', str(touzi_gongbing))
        #确定步兵投资目标
        touzi_bubing = []
        for i in range(len(bu_lists)):
#             ini_generals[qi_lists[i]]
            if self.BL['b%s' % i].isChecked():
                touzi_bubing.append(ini_generals[str(bu_lists[i])])
        setConfig('bulist', str(touzi_bubing))
        #确定车兵投资目标
        touzi_chebing = []
        for i in range(len(che_lists)):
#             ini_generals[qi_lists[i]]
            if self.BL['c%s' % i].isChecked():
                touzi_chebing.append(ini_generals[str(che_lists[i])])
        setConfig('chelist', str(touzi_chebing))
        
        
        qianghua_bingzhong.extend(touzi_qibing)
        qianghua_bingzhong.extend(touzi_gongbing)
        qianghua_bingzhong.extend(touzi_bubing)
        qianghua_bingzhong.extend(touzi_chebing)
        setCache('qianghua_bingzhong', qianghua_bingzhong)
        
        #建筑建造
        cityUpgrade = []
        citybuilding = []
        for i in range(len(citybuilding_lists)):
#             ini_generals[qi_lists[i]]
            if self.BL['citybuilding%s' % i].isChecked():
                citybuilding.append(citybuilding_lists[i])
                if citybuilding_lists[i] == 12:
                    #加入市场
                    cityUpgrade.append(3)
                    cityUpgrade.append(9)
                    cityUpgrade.append(10)
                    cityUpgrade.append(11)
                    cityUpgrade.append(12)
                    cityUpgrade.append(13)
                elif citybuilding_lists[i] == 13:
                    #加入农田
                    cityUpgrade.append(2)
                    cityUpgrade.append(4)
                    cityUpgrade.append(5)
                    cityUpgrade.append(6)
                    cityUpgrade.append(7)
                    cityUpgrade.append(8)
                else:
                    cityUpgrade.append(citybuilding_lists[i])
        setConfig('citybuilding', str(citybuilding))
        setCache('cityUpgrade', cityUpgrade)
        
        #兵法升级
        upgradeBingfas = []
        for i in range(len(bingfa_lists)):
#             ini_generals[qi_lists[i]]
            if self.BL['zhanfa%s' % i].isChecked():
                upgradeBingfas.append(bingfa_lists[i])
        setCache('upgradeBingfas', upgradeBingfas)
        setConfig('bingfas', str(upgradeBingfas))
        
        if self.threeEntry.isChecked():
            three = '1'
        else:
            three = '0'
        if self.threeEntry2.isChecked():
            three2 = '1'
        else:
            three2 = '0'
        #主公宝物升级
        zhugongbaowu = []
        for i in range(len(zhugongbaowu_ini)):
            if self.BL['zhugongbaowu%s' % i].isChecked():
                zhugongbaowu.append(1)
            else:
                zhugongbaowu.append(0)
        setCache('zhugongbaowu', zhugongbaowu)
        setConfig('zhugongbaowu', str(zhugongbaowu))
        
        #是否宝物升级忠诚度
        if self.zhongchengEntry.isChecked():
            zhongchengdu = '1'
        else:
            zhongchengdu = '0'
        setCache('zhongchengdu', zhongchengdu)
        
        
        
        setConfig('pos', str(pos))
        setConfig('guofang', str(guofang))
        setConfig('fires', str(fires))
#         setConfig('bingfa', str(bingfa))
#         setConfig('upgradeBaowu', str(upgradeBaowu))
        setConfig('excepts', str(excepts))
        setConfig('usernames', str(lbusernamess))
        setConfig('three', str(three))
        setConfig('three2', str(three2))
        setConfig('CheckPutong', str(CheckPutong))
        setConfig('CheckGuanka', str(CheckGuanka))
        setConfig('CheckGunshi', str(CheckGunshi))
        setConfig('CheckSenlin', str(CheckSenlin))
        setConfig('CheckCaoyuan', str(CheckCaoyuan))
        setConfig('CheckShuiyu', str(CheckShuiyu))
        setConfig('CheckHuchenghe', str(CheckHuchenghe))
        setConfig('CheckManzucheng', str(CheckManzucheng))
        setConfig('CheckXiagu', str(CheckXiagu))
        setConfig('CheckGangkou', str(CheckGangkou))
        setConfig('zhongcheng', str(zhongchengdu))
        
        prints(u'hosts为'+hosts+u"\nroot为"+root)
        
        
        
        setCache('hosts', str(hosts))
        #选择第几个角色
        setCache('players', str(players))
        setCache('root', str(root))
        setCache('pos', pos)
        setCache('guofang', str(guofang))
        setCache('fires', fires)
#         setCache('bingfa', bingfa)
#         setCache('upgradeBaowu', upgradeBaowu)
        setCache('exceptss', exceptss)
        setCache('three', three)
        setCache('three2', three2)
        
        #禁用按钮
        getCache('loginBtn').setEnabled(False)
        getCache('stopBtn').setEnabled(True)
        
        #启动线程
        self.thread.start()
        
        self.thread.trigger.connect(self.onClearlogButton)
        
        
        self.thread2.start()
        
        
        self.thread3.start()
        self.thread4.start()
        self.thread5.start()
        
        
    @pyqtSlot()
    #跑完后输出
    def threadok(self):
        #只有在self.start.run()
        prints('跑完了')
#         self.thread.stop()
#         self.thread.join()
        self.thread.terminate()
        self.thread2.terminate()
        self.thread3.terminate()
        self.thread4.terminate()
        self.thread5.terminate()
        getCache('loginBtn').setEnabled(True)
        getCache('stopBtn').setEnabled(False)
        
        
    #清空日志按钮
    def onClearlogButton(self):
#         self.thread.clearlog()
        getCache('tab2').setText('')

    #关闭操作按钮
    def onStopButton(self):
        getCache('loginBtn').setEnabled(True)
        getCache('stopBtn').setEnabled(False)
        #强制退出一个线程(terminate)
#         setCache('stopped', 1)
        self.thread.terminate()
        self.thread2.terminate()
        self.thread3.terminate()
        self.thread4.terminate()
        self.thread5.terminate()
#         self.cursor.insertText('线程已关闭\n')
        prints('线程已关闭\n')
    
 
class MainWindow(QtGui.QMainWindow):
    trigger = pyqtSignal()
    def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setWindowIcon(QtGui.QIcon('lb.ico'))
        tabs = QtGui.QTabWidget(self)
        
        #开启程序淡入效果
        #界面动画，改变透明度的方式出现0 - 1渐变
        self.animation = QPropertyAnimation(self, "windowOpacity")
        self.animation.setDuration(1000)
        self.animation.setStartValue(0)
        self.animation.setEndValue(1)
        self.animation.start()
        
        setCache('tabs', tabs)
        tab1 = QtGui.QWidget()    
        vbox = QtGui.QVBoxLayout()
        console = MyConsole(self)
        vbox.addWidget(console)
        tab1.setLayout(vbox)
        tabs.addTab(tab1,u"控制台")
        
        self.tab3 = QTextEdit()
        tabs.addTab(self.tab3,u"ChangeLog")
        self.tab3.setObjectName("textEdit")
        self.cursorss = self.tab3.textCursor()
        self.cursorss.insertText(u'    ps:如若没有更新7.0版本的同学，请先把目录中的config.conf给删除再运行程序')
        self.cursorss.insertText(u'(2016/09/28)7.1更新:庆典期间增加建筑去火\n')
        self.cursorss.insertText(u'(2016/09/28)7.2更新:增加是否大远征/是否1V2选项\n')
        self.cursorss.insertText(u'    ps:如若没有远征目标时，程序会自动选择1V2目标\n')
        self.cursorss.insertText(u'(2016/09/28)7.3更新:建筑去火提前选项\n')
        self.cursorss.insertText(u'    修复市场一未被灭火的bug\n')
        self.cursorss.insertText(u'(2016/09/28)7.4更新:修复大远征\n')
        self.cursorss.insertText(u'(2016/09/29)7.5更新:修复远征攻击本国玩家判断\n')
        self.cursorss.insertText(u'(2016/09/30)7.6更新:修复37N服获取失败\n')
        self.cursorss.insertText(u'(2016/10/02)7.7更新:1V2选择目标修改为选择主+副的玩家等级总和最小\n')
        self.cursorss.insertText(u'(2016/10/02)7.8更新:去除战术选择\n')
        self.cursorss.insertText(u'(2016/10/08)7.9更新:庆典中增加升级武将，输入框填写武将id，填0表示不升级\n')
        self.cursorss.insertText(u'    去除远征未找到目标默认的1V2\n')
        self.cursorss.insertText(u'(2016/10/11)8.0更新:修复武将升级填空bug\n')
        self.cursorss.insertText(u'(2016/10/18)8.1更新:增加国防建设选项\n')
        self.cursorss.insertText(u'    优化远征本方武将选择为阵上武将\n')
        self.cursorss.insertText(u'(2016/10/19)8.2更新:新版本远征优化\n')
        self.cursorss.insertText(u'(2016/10/20)8.3更新:新活动免费次数领取\n')
        self.cursorss.insertText(u'(2016/10/24)8.4更新:加快了庆典、农市和战斗的频率\n')
        self.cursorss.insertText(u'(2016/10/25)8.5更新:增加新版邀功\n')
        self.cursorss.insertText(u'    增加城池自动放谎报、炸弹\n')
        self.cursorss.insertText(u'    增加草船借箭活动免费开船\n')
        self.cursorss.insertText(u'(2016/10/25)8.6更新:优化战场出兵顺序，远征1V2攻击顺序为在阵武将\n')
        self.cursorss.insertText(u'(2016/10/31)8.7更新:捞玉玺免费次数领取\n')
        self.cursorss.insertText(u'(2016/11/07)8.8更新:战场中武将被抓，直接退出战斗\n')
        self.cursorss.insertText(u'(2016/11/08)8.9更新：修复程序卡住\n')
        self.cursorss.insertText(u'(2016/11/08)9.0更新：城防建设升级\n')
        self.cursorss.insertText(u'(2016/11/08)9.1更新：优化国防建设\n')
        self.cursorss.insertText(u'(2016/11/09)9.2更新：国防建设支持最多3个队列同时建造\n')
        self.cursorss.insertText(u'    等级不足或者城池被抢会建造下一档次物品，正在建造此类型物品会建造同类型物品\n')
        self.cursorss.insertText(u'    增加跨服膜拜\n')
        self.cursorss.insertText(u'(2016/11/10)9.3更新：增加远征排除攻击玩家列表\n')
        self.cursorss.insertText(u'    增加草船借箭兵书的免费次数领取\n')
        self.cursorss.insertText(u'(2016/11/11)9.4更新：修复排除远征问题\n')
        self.cursorss.insertText(u'(2016/11/11)9.5更新：修复排除远征问题\n')
        self.cursorss.insertText(u'(2016/11/11)9.6更新：增加1V2排除目标\n')
        self.cursorss.insertText(u'(2016/11/11)9.7更新：远征/1v2排除目标终极优化\n')
        self.cursorss.insertText(u'(2016/11/15)10.0更新：内存处理、各种优化\n')
        self.cursorss.insertText(u'(2016/11/17)10.1更新：加快投兵、释放战法\n')
        self.cursorss.insertText(u'    增加进入大决战\n')
        self.cursorss.insertText(u'(2016/11/21)10.2更新：优化大远征1V2选人机制\n')
        self.cursorss.insertText(u'(2016/11/22)10.3更新：增加新活动七擒孟获、曹操起兵免费次数领取\n')
        self.cursorss.insertText(u'    增加5V5报名与审批以及5V5的战斗\n')
        self.cursorss.insertText(u'    增加免费祭祀\n')
        self.cursorss.insertText(u'(2016/11/24)10.4更新：5V5、大决战优化完美\n')
        self.cursorss.insertText(u'(2016/11/28)10.5更新：优化5V5第三方国家\n')
        self.cursorss.insertText(u'(2016/11/29)10.6更新：优化5V5观看者不战斗bug\n')
        self.cursorss.insertText(u'    加快超出宝石合成\n')
        self.cursorss.insertText(u'(2016/11/29)10.7更新：终极加快宝石合成，去除报错日志\n')
        self.cursorss.insertText(u'(2016/12/09)10.8更新：接受通商优化\n')
        self.cursorss.insertText(u'    取消5V5的报名以及审批\n')
        self.cursorss.insertText(u'(2016/12/09)10.9更新：增加三顾茅庐自动开免费设置\n')
        self.cursorss.insertText(u'(2016/12/09)11.0更新：三顾茅庐修复bug\n')
        self.cursorss.insertText(u'(2016/12/14)11.1更新：增加武将忠诚度自动升级，只保留攻击>=39的宝物\n')
        self.cursorss.insertText(u'(2016/12/15)11.2更新：去除国防建设配置，默认建造牛B建筑\n')
        self.cursorss.insertText(u'(2016/12/15)11.3更新：二星宝石自动合成\n')
        self.cursorss.insertText(u'    官员大理石足够，粮草足够不强弄\n')
        self.cursorss.insertText(u'(2016/12/16)11.4更新：修复武将升级宝物bug\n')
        self.cursorss.insertText(u'(2016/12/16)11.5更新：非常牛B的庆典优化，并优化5V5战斗\n')
        self.cursorss.insertText(u'(2016/12/16)11.6更新：优化大远征：被大远征也能放战术\n')
        self.cursorss.insertText(u'(2016/12/21)11.7更新：临时解决远征，暂时能开打，后续还会优化！！！\n')
        self.cursorss.insertText(u'(2016/12/21)11.8更新：远征优化+跨服远征+小秘书自动领取攻城奖励+庆典优化\n')
        self.cursorss.insertText(u'(2016/12/21)11.9更新：跨服远征只打相差7级以上玩家\n')
        self.cursorss.insertText(u'(2016/12/21)12.0更新：bug,bugbug\n')
        self.cursorss.insertText(u'(2016/12/21)12.1更新：继续修bug\n')
        self.cursorss.insertText(u'(2016/12/21)12.2更新：庆典完美优化，呵呵\n')
        self.cursorss.insertText(u'(2016/12/22)12.3更新：大理石矿放宽条件\n')
        self.cursorss.insertText(u'(2016/12/22)12.4更新：增加网络阻塞重连机制\n')
        self.cursorss.insertText(u'(2016/12/22)12.5更新：增加空闲期间自动募兵\n')
        self.cursorss.insertText(u'(2016/12/22)12.6更新：改为庆典开始才去清理闹事\n')
        self.cursorss.insertText(u'(2016/12/22)12.7更新：加速锤全建筑都用\n')
        self.cursorss.insertText(u'(2016/12/27)12.8更新：七擒孟获暂时弃用\n')
        self.cursorss.insertText(u'(2016/12/28)12.9更新：1V2辅助方也进排除名单\n')
        self.cursorss.insertText(u'(2016/12/28)13.0更新：2017元旦活动\n')
        self.cursorss.insertText(u'(2017/01/05)13.1更新：增加远征进度满优先远征\n')
        self.cursorss.insertText(u'(2016/01/05)13.2更新：增加跨服的膜拜\n')
        self.cursorss.insertText(u'(2016/01/05)13.3更新：加入夜战，优化国战，在阵攻击方4人以下才进入该城战\n')
        self.cursorss.insertText(u'(2016/01/05)13.4更新：优化国战和远征\n')
        self.cursorss.insertText(u'(2016/01/05)13.5更新：再优化国战和远征\n')
        self.cursorss.insertText(u'(2016/01/07)13.6更新：修复远征4将不打国战bug\n')
        self.cursorss.insertText(u'(2016/01/07)13.7更新：跨服金杯优化\n')
        self.cursorss.insertText(u'(2016/01/09)13.8更新：远征选人优化\n')
        self.cursorss.insertText(u'(2016/01/10)13.9更新：小秘书免费领取+免费小经验车队\n')
        self.cursorss.insertText(u'(2016/01/10)15.0更新：远征进度50%下用kf膜拜\n')
        self.cursorss.insertText(u'(2016/01/10)15.1更新：三顾茅庐宝石版\n')
        self.cursorss.insertText(u'(2016/01/10)15.2更新：修复远征进度（必更）\n')
        self.cursorss.insertText(u'(2016/01/11)15.3更新：国战可选择喜好类型城池\n')
        self.cursorss.insertText(u'(2016/01/11)15.5更新：文官事件优化\n')
        self.cursorss.insertText(u'(2016/01/11)15.6更新：修复各种error\n')
        self.cursorss.insertText(u'(2016/01/11)15.7更新：投资武将时间优化\n')
        self.cursorss.insertText(u'(2016/01/16)15.8更新：增加建筑升级、文官事件、武将升级、战法升级可选项\n')
        self.cursorss.insertText(u'(2016/01/16)15.9更新：1V2限定守方为低于玩家2级以下玩家\n')
        self.cursorss.insertText(u'(2016/01/16)16.0更新：忠诚度升级和武将强化分开\n')
        self.cursorss.insertText(u'(2016/01/18)16.1更新：修复酒馆抢将成功后不招募的bug\n')
        self.cursorss.insertText(u'(2016/01/19)16.2更新：修复忠诚度bug\n')
        self.cursorss.insertText(u'(2016/01/22)16.3更新：增加主公宝物升级\n')
        self.cursorss.insertText(u'(2016/01/22)16.4更新：宝物忠诚度升级可选项\n')
        self.cursorss.insertText(u'    远征各种判断修复\n')
        self.cursorss.insertText(u'(2016/01/23)16.5更新：远征判断修复\n')
        self.cursorss.insertText(u'(2016/01/23)16.6更新：春节红包活动\n')
        self.cursorss.insertText(u'(2016/01/24)16.7更新：加入十星宝石雕像膜拜\n')
        self.cursorss.insertText(u'    银币转盘花费选择\n')
        self.cursorss.insertText(u'    春节红包活动随着后端一起更改\n')
        self.cursorss.insertText(u'(2016/02/14)16.8更新：增加远征分兵选项\n')
        self.cursorss.insertText(u'(2016/02/17)16.9更新：修复三顾茅庐免费次数不使用的bug\n')
        self.cursorss.insertText(u'(2016/02/22)17.0重要更新：主城建筑升级优化：均匀升级\n')
        self.cursorss.insertText(u'(2016/02/23)17.1重要更新：建筑升级优化：大理石不足的时候不升级建筑修复\n')
        self.cursorss.insertText(u'(2016/02/28)17.2重要更新：国家擂台领取奖励\n')
        self.cursorss.insertText(u'(2016/03/06)17.3重要更新：修复膜拜十星宝石\n')
        self.cursorss.insertText(u'(2016/03/07)17.5重要更新：增加是否永久武将选项\n')
        self.cursorss.insertText(u'(2016/03/14)17.6重要更新：增加神级兵法升级\n')
        self.cursorss.insertText(u'(2016/03/30)17.7重要更新：增加捞宝物免费开/金币开，默认开宝石\n')
        
        
#         palette = QPalette()
#         palette.setBrush(QPalette.Background,QBrush(QPixmap("jay.jpg")))
#         tabs.setPalette(palette)
#         tabs.show()
        
        
        tabs.resize(700, 650)
        self.resize(700, 650)
        
        #禁止最大化
        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)  
        self.show()
#         QThread.sleep(2)  
        
    def __del__(self):
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
        
    
    #按ESC关闭程序
    def keyPressEvent(self, event):
        if event.key() ==QtCore.Qt.Key_Escape:
            self.close()
    
    
def resource_path(self,relative):
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)
        return os.path.join(relative)    
    
def main():
    app=0           #This is the solution
    app = QtGui.QApplication(sys.argv)
    
#     import Tkinter
#     photo=Tkinter.PhotoImage(file=resource_path('la.png'))
#     Tkinter.Canvas.create_image(240,35,image =photo)
#     from ico import _ico
#     print _ico.GetIcon()
    #程序启动动画
#     splash=QSplashScreen(QPixmap("la.png"))  
#     splash=QSplashScreen(_ico.GetIcon())  
#     splash.show()  
    app.processEvents()
#     time.sleep(2)
    win = MainWindow()
    #窗体标题
    win.setWindowTitle("乱世小助手17.7")
#     splash.finish(win) 
    sys.exit(app.exec_())
    
    
    
if __name__ == '__main__':
    main()

